<!DOCTYPE html>
<html>
<head>
    <link rel="stylesheet" href="../../lib/layui/css/layui.css">
    <link rel="stylesheet" href="../../css/oksub.css">
    <meta charset="utf-8">
    <title></title>
    <style>
        /* 添加教师页面样式 */
        .addtea-con{
            padding:0 15px 15px 15px;
            margin-bottom: 40px;
        }
        .addtea-con .top-inp{
            margin-left: 20px;
        }
        .addtea-con .from-con{
            margin: auto;
            background-color: #fdfcfc;
            padding: 10px;
            overflow: hidden;
        }
        .addtea-con .from-con .layui-form-item{
            margin:20px 0 ;
        }
        .addtea-con .not_border_left {
            border-left: none !important;
        }
        .addtea-con .layui-form-item .layui-input-block .required {
            color: #ffb800;
            font-size: 32px;
            float: left;
            margin-left: 5px;
            margin-top: 5px;
            position: absolute;
            right: -15px;
        }
        .addtea-con .layui-form-select dl dd.layui-this{
            background-color: #1E9FFF !important;
        }
        .addtea-con .layui-btn{
            background-color: #1E9FFF !important;
        }
        .addtea-con .layui-form-select dl{
            max-height:230px !important;
        }
    </style>
</head>
<body>
<!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
<!--[if lt IE 9]>
<script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
<script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>部门管理</legend>
</fieldset>
<div class="addtea-con">
    <div class="from-con">
        <div style="width: 60%;padding-bottom:100px;margin: 0 auto;">
            <form class="layui-form" style="margin-left: -90px" action="" id="formaddtea">
                <div class="layui-row">
                    <div class="layui-col-xs6">
                        <div class="layui-form-item" style="margin-right: 15%">
                            <label class="layui-form-label">部门ID&#12288;</label>
                            <div class="layui-input-block">
                                <input id="departmentId" name="departmentId" type="text" style="float: left;position: relative;" lay-verify="required" placeholder="请输入部门ID" class="layui-input" autocomplete="off">
                                <i class="required">*</i>
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-xs6">
                        <div class="layui-form-item" style="margin-left: 15%">
                            <label class="layui-form-label">部门名称</label>
                            <div class="layui-input-block">
                                <input id="departmentName" name="departmentName" type="text" style="float: left;position: relative;" class="layui-input" placeholder="请输入部门名称" lay-verify="required" autocomplete="off">
                                <i class="required">*</i>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-row">
                    <div class="layui-col-xs6">
                        <div class="layui-form-item" style="margin-right: 15%">
                            <label class="layui-form-label">类&#12288;&#12288;型</label>
                            <div class="layui-input-block">
                                <i class="required">*</i>
                                <select name="deepth" id="deepth" style="float: left;position: relative;" lay-verify="required">
                                    <option selected="" value="0">请选择类型</option>
                                    <option value="3">派出所</option>
                                    <option value="2">指挥中心</option>
                                    <option value="1">公安局</option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-xs6">
                        <div class="layui-form-item" style="margin-left: 15%">
                            <label class="layui-form-label">部门描述</label>
                            <div class="layui-input-block">
                                <input id="description" name="description" type="text" style="float: left;position: relative;" class="layui-input" placeholder="请输入部门名称" autocomplete="off">
                            </div>
                        </div>
                    </div>
                </div>

                <div class="layui-form-item" style="margin-top: 40px">
                    <div class="layui-input-block">
                        <button type="button" id="addParent" lay-submit="" lay-filter="addParent" class="layui-btn" style="float: right;"> 保  存 </button>
                    </div>
                </div>
            </form>
        </div>
    </div>
    <!--添加教师表单End-->
</div>
</body>
<script src="../../lib/layui/layui.js"></script>
<script src="../../js/jquery.min.js"></script>
<script src="../../js/application.js"></script>

<script>
    layui.use(['form', 'layer'], function(){
        var form = layui.form;
        var layer= layui.layer

        //通过表单验证之后才会执行
        //部门信息添加
        form.on('submit(addParent)', function(teadata){
            showloading(true)
            var departmentId=$("#departmentId").val();//获取到输入的部门编号
            var departmentName=$("#departmentName").val();//获取输入部门名称
            var description=$("#description").val();//获取部门描述
             var deepth=$("#deepth").val();//获取选择的部门类型
            if(deepth==0){
                layer.msg("请选择所属类型！");
                return false;
            }
            $.ajax({
                url:mainUri+"/dep/insert",
                type: 'get',
                dataType: 'json',
                data:{departmentId:departmentId,departmentName:departmentName,description:description,deepth:deepth},
                success: function (data) {
                    showloading(false)//关闭等待遮罩
                    if (data.code == 0) {
                        layer.alert('部门信息添加成功了！', {icon: 6});
                        $("input").val('');
                        return false;
                    }else if(data.code=='-9999'){
                        layer.alert('此部门已经存在了！', {icon: 2});
                        $("input").val('');
                        return false;
                    }
                    else{
                        layer.alert('部门信息添加失败了！', {icon: 2});
                        $("input").val('');
                        return false;
                    }
                },
                error:function(){
                    showloading(false)
                    layer.alert('添加异常！', {icon: 2});
                }
            });
        });

    });
</script>
</html>
